<template>
    <div class="app-container">
        <div class="head">
            <img src="@/assets/img/Layout/position.png" />
            <p class="see-block">销售退货详情</p>
        </div>
        <div class="view-container">
            <el-row class="status-title">
                <template v-if="detailData.dataType !== '5'">
                    <el-col class="mr20 width100" v-if="detailData.approvalStatus == '1'">
                        <el-button
                            class="btn-default width100"
                            type="primary"
                            @click="audit()"
                            v-hasPermi="['system:salesReturnOrder:updateStatus']"
                        >审核</el-button>
                    </el-col>
                    <el-col class="mr20 width100" v-if="detailData.approvalStatus == '2'">
                        <el-button
                            class="btn-audit width100"
                            type="primary"
                            @click="theAudit()"
                            v-hasPermi="['system:salesReturnOrder:updateStatus']"
                        >反审核</el-button>
                    </el-col>
                    <el-col class="mr20 width100" v-if="detailData.approvalStatus == '0' || detailData.approvalStatus == '3'">
                        <el-button
                            class="btn-default width100"
                            type="primary"
                            @click="edit()"
                            v-hasPermi="['system:salesReturnOrder:update']"
                        >编辑</el-button>
                    </el-col>
                </template>
                <el-col :span="10" class="status-container">
                    <div class="status-item">
                        <span :class="{ 'active' : detailData.approvalStatus == '0'}">草稿</span>
                        <span :class="{ 'active' : detailData.approvalStatus == '1'}">待审核</span>
                        <span :class="{ 'active' : detailData.approvalStatus == '2'}">已审核</span>
                        <span :class="{ 'active' : detailData.approvalStatus == '3'}">拒绝</span>
                    </div>
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="8">
                    <span>订单编码：</span>{{ detailData.code ?  detailData.code : '暂无'}}
                </el-col>
                <el-col :span="9">
                    <span>业务日期：</span>{{ detailData.businessDate ?  detailData.businessDate : '暂无'}}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="8">
                    <span>业务模式：</span>{{ detailData.businessModel == '0' ?  '销售退货' : '暂无'}}
                </el-col>
                <el-col :span="8">
                    <span>订单类型：</span>{{ detailData.orderType == '0' ?  '普通' : '暂无'}}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="8">
                    <span>客户类型：</span>{{ detailData.customerType == '1' ?  '企业客户' : detailData.customerType == '2' ? '会员' :  '暂无'}}
                </el-col>
                <el-col :span="8">
                    <span>客户名称：</span>{{ detailData.customerName ?  detailData.customerName : '暂无'}}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="8">
                    <span>是否有源单：</span>{{ detailData.haveOrNot == '1' ? '是' : '暂无'}}
                </el-col>
                <el-col :span="8">
                    <span>是否全退：</span>{{ detailData.allOrNot == '1' ? '是' : detailData.allOrNot == '0' ? '否' : '暂无' }}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="8">
                    <span>源销售订单：</span>{{ detailData.salesOrderCode ? detailData.salesOrderCode : '暂无' }}
                </el-col>
                <el-col :span="8">
                    <span>退货原因：</span>{{ detailData.reasonForReturn ? detailData.reasonForReturn : '暂无' }}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="8">
                    <span>联系人：</span>{{ detailData.contactName ? detailData.contactName : '暂无' }}
                </el-col>
                <el-col :span="8">
                    <span>联系电话：</span>{{ detailData.contactTel ? detailData.contactTel : '暂无' }}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="8">
                    <span>销售部门：</span>{{ detailData.businessUnit ? detailData.businessUnit : '暂无' }}
                </el-col>
                <el-col :span="8">
                    <span>备注：</span>{{ detailData.remark ? detailData.remark : '暂无' }}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="8">
                    <span>提交人：</span>{{ detailData.createBy ? detailData.createBy : '暂无' }}
                </el-col>
                <el-col :span="8">
                    <span>提交时间：</span>{{ detailData.createTime ? detailData.createTime : '暂无' }}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="8">
                    <span>审核人：</span>{{ detailData.approvalBy ? detailData.approvalBy : '暂无' }}
                </el-col>
                <el-col :span="8">
                    <span>审核时间：</span>{{ detailData.approvalTime ? detailData.approvalTime : '暂无' }}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="8">
                    <span>审核状态：</span>
                    <font v-if="detailData.approvalStatus == 0" style="color:#13C2C2">草稿</font>
                    <font v-if="detailData.approvalStatus == 1" style="color:#13C2C2">待审核</font>
                    <font v-if="detailData.approvalStatus == 2" style="color:#52C41A">已审核</font>
                    <font v-if="detailData.approvalStatus == 3" style="color:#fd562c">未通过</font>
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="24">
                    <el-table :data="detailData.salesReturnOrderDetailList" border>
                        <el-table-column label="序号" type="index" align="center" width="50" />
                        <el-table-column :label="item.label" :prop="item.prop" :width="item.width" v-for="(item, index) in columns" :key="index" align="center">
                        <template slot-scope="scope">
                            <span>{{ scope.row[item.prop] }}</span>
                        </template>
                        </el-table-column>
                    </el-table>
                </el-col>
            </el-row>
        </div>
        <!-- 审核 -->
        <el-dialog :visible.sync="open" width="500" top="100px" append-to-body title="审核意见" center>
            <el-row>
                <el-col :span="24">
                    <textarea
                        class="approve-textarea"
                        v-model="approveRemark"
                        type="textarea"
                        placeholder="请输入意见和看法"
                    />
                </el-col>
            </el-row>
            <div slot="footer" class="dialog-footer">
                <el-button
                    type="primary"
                    class="btn-success mr20 width100"
                    @click="agreeApprove()"
                >同意</el-button>
                <el-button
                    type="primary"
                    class="btn-cancel width100"
                    @click="disagreeApprove()"
                >拒绝</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { returnDetail, returnAudit } from "@/api/system/salesReturn/salesReturn"
export default {
    name: "detail",
    data() {
        return {
            id: '',
            detailData: '',
            // 表头
            columns: [{
              prop: "productBasicCode",
              label: "产品编码",
              width: 150,
            },{
              prop: "specificationCode",
              label: "SKU编码",
              width: 150,
            },{
              prop: "productBasicName",
              label: "产品名称",
              width: 150,
            },
            {
                prop: "productSpace",
                label: "规格",
            },{
                prop: "unit",
                label: "单位",
            },{
                prop: "unitPrice",
                label: "单价",
            },{
                prop: "planNum",
                label: "申退数量",
            },
            {
                prop: "warehouseName",
                label: "仓库",
            },
            {
                prop: "remark",
                label: "备注",
            }],
            open: false,
            approveRemark: ''
        }
    },
    created(){
        this.id = this.$route.query.id
        this.getDetailData()
    },
    methods: {
        // 获取详情数据
        getDetailData(){
            returnDetail(this.id).then(res => {
                this.detailData = res.data
            })
        },
        // 审核
        audit(){
            this.open = true
        },
        // 通过
        agreeApprove(){
            returnAudit({id: this.id, approvalStatus: 2}).then(res => {
                if(res.code == 200){
                    this.open = false
                    this.$modal.msgSuccess("操作成功")
                    this.$tab.closeOpenPage({ path: "/sales/salesReturn/list" })
                }
            })
        },
        // 拒绝
        disagreeApprove(){
            returnAudit({id: this.id, approvalStatus: 3}).then(res => {
                if(res.code == 200){
                    this.open = false
                    this.$modal.msgSuccess("操作成功")
                    this.$tab.closeOpenPage({ path: "/sales/salesReturn/list" })
                }
            })
        },
        // 反审核
        theAudit(){
            this.$modal.confirm('是否确认反审核？', '反审核').then(() => {
                returnAudit({id: this.id, approvalStatus: 0}).then(res => {
                    if(res.code == 200){
                        this.open = false
                        this.$modal.msgSuccess("操作成功")
                        this.$tab.closeOpenPage({ path: "/sales/salesReturn/list" })
                    }
                })
            }).catch(() => {})
        },
        // 编辑
        edit(){
            this.$tab.closeOpenPage({ path: "/sales/salesReturn/edit", query:{id: this.id} })
        }
    }
}
</script>
